#!/usr/bin/env python

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import datetime
from django.utils import simplejson
import cgi

from model import ClassState
from model import Lecture
from model import Course
from model import Lecturer

class MyHandler(webapp.RequestHandler):
    def get(self):
        states = db.Query(ClassState)

        currentActiveStates = []

        for s in states:
            obj = { "lecture": s.lecture.name, "course":s.lecture.course.name, "lectureKey":str(s.lecture.key()) }
            currentActiveStates.append(obj)

        self.response.out.write(simplejson.dumps(currentActiveStates))
    
app = webapp.WSGIApplication([(r'.*', MyHandler)], debug=True)

def main():
    wsgiref.handlers.CGIHandler().run(app)

if __name__ == "__main__":
    main()